

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="dayu">
  <meta name="keywords" content="">
  
    <meta name="description" content="销量趋势分析代码环境的准备TrendPage.vue 12345678910111213141516171819202122&lt;!--针对于 &#x2F;trendpage 这条路径而显示出来的在这个组件中, 通过子组件注册的方式, 要显示出Trend.vue这个组件--&gt;&lt;template&gt;  &lt;div class&#x3D;&quot;com-page&quot;&gt;    &amp;lt">
<meta property="og:type" content="article">
<meta property="og:title" content="数据可视化项目四">
<meta property="og:url" content="http://example.com/2022/11/17/%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96%E9%A1%B9%E7%9B%AE%E5%9B%9B/index.html">
<meta property="og:site_name" content="Dayu">
<meta property="og:description" content="销量趋势分析代码环境的准备TrendPage.vue 12345678910111213141516171819202122&lt;!--针对于 &#x2F;trendpage 这条路径而显示出来的在这个组件中, 通过子组件注册的方式, 要显示出Trend.vue这个组件--&gt;&lt;template&gt;  &lt;div class&#x3D;&quot;com-page&quot;&gt;    &amp;lt">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-11-17T04:19:16.000Z">
<meta property="article:modified_time" content="2023-09-05T13:21:06.626Z">
<meta property="article:author" content="dayu">
<meta property="article:tag" content="echarts">
<meta name="twitter:card" content="summary_large_image">
  
  
  
  <title>数据可视化项目四 - Dayu</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.3","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>dayu</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="数据可视化项目四"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-11-17 12:19" pubdate>
          2022年11月17日 中午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          11k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          91 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">数据可视化项目四</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="销量趋势分析"><a href="#销量趋势分析" class="headerlink" title="销量趋势分析"></a>销量趋势分析</h1><h2 id="代码环境的准备"><a href="#代码环境的准备" class="headerlink" title="代码环境的准备"></a>代码环境的准备</h2><p><code>TrendPage.vue</code></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;!--<br>针对于 /trendpage 这条路径而显示出来的<br>在这个组件中, 通过子组件注册的方式, 要显示出Trend.vue这个组件<br>--&gt;<br>&lt;template&gt;<br>  &lt;div class=&quot;com-page&quot;&gt;<br>    &lt;trend&gt;&lt;/trend&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>import Trend from &#x27;@/components/Trend&#x27;<br>export default &#123;<br>  data() &#123;<br>    return &#123;&#125;<br>  &#125;,<br>  methods: &#123;&#125;,<br>  components: &#123;<br>    trend: Trend,<br>  &#125;,<br>&#125;<br>&lt;/script&gt;<br>&lt;style lang=&quot;less&quot; scoped&gt;&lt;/style&gt;<br></code></pre></td></tr></table></figure>

<p><code>Trend.vue</code></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;!-- 销量趋势图表 --&gt;<br>&lt;template&gt;<br>  &lt;div class=&quot;com-container&quot;&gt;<br>    &lt;div class=&quot;com-chart&quot; ref=&quot;trend_ref&quot;&gt;&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>export default &#123;<br>  data() &#123;<br>    return &#123;<br>      chartInstance: null,<br>      allData: null,<br>    &#125;<br>  &#125;,<br>  mounted() &#123;<br>    this.initChart()<br>    this.getData()<br>    window.addEventListener(&#x27;resize&#x27;, this.screenAdapter)<br>    this.screenAdapter()<br>  &#125;,<br>  destroyed() &#123;<br>    window.removeEventListener(&#x27;resize&#x27;, this.screenAdapter)<br>  &#125;,<br>  methods: &#123;<br>    initChart() &#123;<br>      this.chartInstance = this.$echarts.init(this.$refs.trend_ref)<br>      const initOption = &#123;&#125;<br>      this.chartInstance.setOption(initOption)<br>    &#125;,<br>    async getData() &#123;<br>      // 获取服务器的数据, 对this.allData进行赋值之后, 调用updateChart方法更新图表<br>      this.updateChart()<br>    &#125;,<br>    updateChart() &#123;<br>      // 处理图表需要的数据<br>      const dataOption = &#123;&#125;<br>      this.chartInstance.setOption(dataOption)<br>    &#125;,<br>    screenAdapter() &#123;<br>      const adapterOption = &#123;&#125;<br>      this.chartInstance.setOption(adapterOption)<br>      this.chartInstance.resize()<br>    &#125;,<br>  &#125;,<br>&#125;<br>&lt;/script&gt;<br>&lt;style lang=&quot;less&quot; scoped&gt;&lt;/style&gt;<br></code></pre></td></tr></table></figure>

<p><code>router/index.js</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs js">......<br><span class="hljs-keyword">import</span> <span class="hljs-title class_">TrendPage</span> <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@/views/TrendPage&#x27;</span><br>......<br><span class="hljs-keyword">const</span> routes = [<br>......<br>&#123;<br><span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/trendpage&#x27;</span>,<br><span class="hljs-attr">component</span>: <span class="hljs-title class_">TrendPage</span><br>&#125;<br>]<br>......<br><br></code></pre></td></tr></table></figure>

<h2 id="图表基本功能的实现"><a href="#图表基本功能的实现" class="headerlink" title="图表基本功能的实现"></a>图表基本功能的实现</h2><ul>
<li><p>数据的获取</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">async</span> getData () &#123;<br><span class="hljs-comment">// 获取服务器的数据, 对this.allData进行赋值之后, 调用updateChart方法更新图表</span><br><span class="hljs-keyword">const</span> &#123; <span class="hljs-attr">data</span>: ret &#125; = <span class="hljs-keyword">await</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">$http</span>.<span class="hljs-title function_">get</span>(<span class="hljs-string">&#x27;trend&#x27;</span>)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span> = ret<br><span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateChart</span>()<br>&#125;<br><br></code></pre></td></tr></table></figure></li>
<li><p>数据的处理</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br><span class="hljs-comment">// x轴的数据</span><br><span class="hljs-keyword">const</span> timeArrs = <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>.<span class="hljs-property">common</span>.<span class="hljs-property">month</span><br><span class="hljs-comment">// y轴的数据, 暂时先取出map这个节点的数据</span><br><span class="hljs-comment">// map代表地区销量趋势</span><br><span class="hljs-comment">// seller代表商家销量趋势</span><br><span class="hljs-comment">// commodity代表商品销量趋势</span><br><span class="hljs-keyword">const</span> valueArrs = <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>.<span class="hljs-property">map</span>.<span class="hljs-property">data</span><br><span class="hljs-comment">// 图表数据, 一个图表中显示5条折线图</span><br><span class="hljs-keyword">const</span> seriesArr = valueArrs.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br><span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;line&#x27;</span>, <span class="hljs-comment">// 折线图</span><br><span class="hljs-attr">name</span>: item.<span class="hljs-property">name</span>,<br><span class="hljs-attr">data</span>: item.<span class="hljs-property">data</span>,<br>&#125;<br>&#125;)<br><span class="hljs-keyword">const</span> dataOption = &#123;<br><span class="hljs-attr">xAxis</span>: &#123;<br><span class="hljs-attr">data</span>: timeArrs<br>&#125;,<br><span class="hljs-attr">legend</span>: &#123;<br><span class="hljs-attr">data</span>: legendArr<br>&#125;,<br><span class="hljs-attr">series</span>: seriesArr<br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">setOption</span>(dataOption)<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>初始化配置</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">const</span> initOption = &#123;<br>  <span class="hljs-attr">xAxis</span>: &#123;<br>    <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;category&#x27;</span>,<br>    <span class="hljs-attr">boundaryGap</span>: <span class="hljs-literal">false</span>,<br>  &#125;,<br>  <span class="hljs-attr">yAxis</span>: &#123;<br>    <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;value&#x27;</span>,<br>  &#125;,<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>堆叠图效果</p>
<p>要实现堆叠图的效果, series 下的每个对象都需要配置上相同的 stack 属性</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br><span class="hljs-keyword">const</span> timeArrs = <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>.<span class="hljs-property">common</span>.<span class="hljs-property">month</span><br><span class="hljs-keyword">const</span> valueArrs = <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>.<span class="hljs-property">map</span>.<span class="hljs-property">data</span><br><span class="hljs-keyword">const</span> seriesArr = valueArrs.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br><span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;line&#x27;</span>,<br><span class="hljs-attr">name</span>: item.<span class="hljs-property">name</span>,<br><span class="hljs-attr">data</span>: item.<span class="hljs-property">data</span>,<br><span class="hljs-attr">stack</span>: <span class="hljs-string">&#x27;map&#x27;</span> <span class="hljs-comment">// stack值相同, 可以形成堆叠图效果</span><br>&#125;<br>&#125;)<br>......<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>图例效果</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br>......<br><span class="hljs-keyword">const</span> valueArrs = <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>.<span class="hljs-property">map</span>.<span class="hljs-property">data</span><br><span class="hljs-keyword">const</span> seriesArr = valueArrs.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br><span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;line&#x27;</span>,<br><span class="hljs-attr">name</span>: item.<span class="hljs-property">name</span>,<br><span class="hljs-attr">data</span>: item.<span class="hljs-property">data</span>,<br><span class="hljs-attr">stack</span>: <span class="hljs-string">&#x27;map&#x27;</span><br>&#125;<br>&#125;)<br><span class="hljs-comment">// 准备图例数据, 它需要和series下的每个对象的name属性保持一致</span><br><span class="hljs-keyword">const</span> legendArr = valueArrs.<span class="hljs-title function_">map</span>(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> item.<span class="hljs-property">name</span><br>&#125;)<br><span class="hljs-keyword">const</span> dataOption = &#123;<br>......<br><span class="hljs-attr">legend</span>: &#123;<br><span class="hljs-attr">data</span>: legendArr<br>&#125;<br>......<br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">setOption</span>(dataOption)<br>&#125;<br><br></code></pre></td></tr></table></figure></li>
</ul>
<h2 id="UI-效果的调整"><a href="#UI-效果的调整" class="headerlink" title="UI 效果的调整"></a>UI 效果的调整</h2><ul>
<li><p>主题的使用</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs js">initChart () &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">$echarts</span>.<span class="hljs-title function_">init</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">$refs</span>.<span class="hljs-property">trend_ref</span>, <span class="hljs-string">&#x27;chalk&#x27;</span>)<br>&#125;<br></code></pre></td></tr></table></figure>

<p>主题使用完之后, 发现折线图都变成了平滑折线图了, 这是因为在 <code>chalk.js </code>主题文件中, 设置了 <code>smooth:true</code></p>
</li>
<li><p>坐标轴大小和位置</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">const</span> initOption = &#123;<br>  <span class="hljs-attr">grid</span>: &#123;<br>    <span class="hljs-attr">top</span>: <span class="hljs-string">&#x27;35%&#x27;</span>,<br>    <span class="hljs-attr">left</span>: <span class="hljs-string">&#x27;3%&#x27;</span>,<br>    <span class="hljs-attr">right</span>: <span class="hljs-string">&#x27;4%&#x27;</span>,<br>    <span class="hljs-attr">bottom</span>: <span class="hljs-string">&#x27;1%&#x27;</span>,<br>    <span class="hljs-attr">containLabel</span>: <span class="hljs-literal">true</span>,<br>  &#125;,<br>  <span class="hljs-attr">tooltip</span>: &#123;<br>    <span class="hljs-attr">trigger</span>: <span class="hljs-string">&#x27;axis&#x27;</span>,<br>  &#125;,<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>工具提示</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">const</span> initOption = &#123;<br>......<br><span class="hljs-attr">tooltip</span>: &#123;<br><span class="hljs-attr">trigger</span>: <span class="hljs-string">&#x27;axis&#x27;</span><br>&#125;<br>......<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>图例位置和形状</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">const</span> initOption = &#123;<br>......<br><span class="hljs-attr">legend</span>: &#123;<br><span class="hljs-attr">top</span>: <span class="hljs-string">&#x27;15%&#x27;</span>,<br><span class="hljs-attr">icon</span>: <span class="hljs-string">&#x27;circle&#x27;</span>,<br><span class="hljs-attr">left</span>: <span class="hljs-number">20</span><br>&#125;,<br>......<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>区域面积的设置</p>
<p>区域面积只需要给 series 的每一个对象增加一个 <code>areaStyle </code>即可</p>
</li>
<li><p>颜色渐变的设置</p>
<p>颜色渐变可以通过 <code>LinearGradient</code> 进行设置, 颜色渐变的方向从上往下</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br><span class="hljs-comment">// 半透明的颜色值</span><br><span class="hljs-keyword">const</span> colorArr1 = [<br><span class="hljs-string">&#x27;rgba(11, 168, 44, 0.5)&#x27;</span>,<br><span class="hljs-string">&#x27;rgba(44, 110, 255, 0.5)&#x27;</span>,<br><span class="hljs-string">&#x27;rgba(22, 242, 217, 0.5)&#x27;</span>,<br><span class="hljs-string">&#x27;rgba(254, 33, 30, 0.5)&#x27;</span>,<br><span class="hljs-string">&#x27;rgba(250, 105, 0, 0.5)&#x27;</span><br>]<br><span class="hljs-comment">// 全透明的颜色值</span><br><span class="hljs-keyword">const</span> colorArr2 = [<br><span class="hljs-string">&#x27;rgba(11, 168, 44, 0)&#x27;</span>,<br><span class="hljs-string">&#x27;rgba(44, 110, 255, 0)&#x27;</span>,<br><span class="hljs-string">&#x27;rgba(22, 242, 217, 0)&#x27;</span>,<br><span class="hljs-string">&#x27;rgba(254, 33, 30, 0)&#x27;</span>,<br><span class="hljs-string">&#x27;rgba(250, 105, 0, 0)&#x27;</span><br>]<br>......<br><span class="hljs-keyword">const</span> seriesArr = valueArrs.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br>......<br><span class="hljs-attr">areaStyle</span>: &#123;<br><span class="hljs-attr">color</span>: <span class="hljs-keyword">new</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">$echarts</span>.<span class="hljs-property">graphic</span>.<span class="hljs-title class_">LinearGradient</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>,<br>[<br>&#123;<br><span class="hljs-attr">offset</span>: <span class="hljs-number">0</span>,<br><span class="hljs-attr">color</span>: colorArr1[index]<br>&#125;,<br>&#123;<br><span class="hljs-attr">offset</span>: <span class="hljs-number">1</span>,<br><span class="hljs-attr">color</span>: colorArr2[index]<br>&#125;<br>])<br>&#125;,<br><span class="hljs-attr">stack</span>: <span class="hljs-string">&#x27;map&#x27;</span><br>&#125;<br>&#125;)<br>......<br></code></pre></td></tr></table></figure></li>
</ul>
<h2 id="切换图表"><a href="#切换图表" class="headerlink" title="切换图表"></a>切换图表</h2><ul>
<li><p>布局的实现</p>
<p>增加类样式为 title 的容器</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div class=&quot;com-container&quot;&gt;<br>    &lt;div class=&quot;title&quot;&gt;<br>      &lt;span&gt;我是标题&lt;/span&gt;<br>      &lt;span class=&quot;iconfont title-icon&quot;&gt;&amp;#xe6eb;&lt;/span&gt;<br>      &lt;div class=&quot;select-con&quot;&gt;<br>        &lt;div class=&quot;select-item&quot;&gt;标题选择1&lt;/div&gt;<br>        &lt;div class=&quot;select-item&quot;&gt;标题选择2&lt;/div&gt;<br>        &lt;div class=&quot;select-item&quot;&gt;标题选择3&lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;com-chart&quot; ref=&quot;trend_ref&quot;&gt;&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br></code></pre></td></tr></table></figure>

<p>字体文件的引入</p>
<p>将资料文件夹下的字体文件夹中的 font 复制到 asset 目录下, 然后在 <code>main.js</code> 中引入字体样式文件</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// 引入字体文件</span><br><span class="hljs-keyword">import</span> <span class="hljs-string">&#x27;./assets/font/iconfont.css&#x27;</span><br></code></pre></td></tr></table></figure>

<p>在 <code>Trend.vue</code> 中的 style 标签中增加一些样式</p>
<figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs less">&lt;<span class="hljs-selector-tag">style</span> <span class="hljs-selector-tag">lang</span>=&#x27;<span class="hljs-selector-tag">less</span>&#x27; <span class="hljs-selector-tag">scoped</span>&gt;<br><span class="hljs-selector-class">.title</span> &#123;<br><span class="hljs-attribute">position</span>: absolute;<br><span class="hljs-attribute">left</span>: <span class="hljs-number">20px</span>;<br><span class="hljs-attribute">top</span>: <span class="hljs-number">20px</span>;<br><span class="hljs-attribute">z-index</span>: <span class="hljs-number">10</span>;<br><span class="hljs-attribute">color</span>: white;<br><span class="hljs-selector-class">.title-icon</span> &#123;<br><span class="hljs-attribute">margin-left</span>: <span class="hljs-number">10px</span>;<br><span class="hljs-attribute">cursor</span>: pointer;<br>&#125;<br><span class="hljs-selector-class">.select-item</span> &#123;<br><span class="hljs-attribute">cursor</span>: pointer;<br>&#125;<br>&#125;<br>&lt;/<span class="hljs-selector-tag">style</span>&gt;<br></code></pre></td></tr></table></figure></li>
<li><p>数据动态渲染</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;!-- 销量趋势图表 --&gt;<br>&lt;template&gt;<br>  &lt;div class=&quot;com-container&quot;&gt;<br>    &lt;div class=&quot;title&quot;&gt;<br>      &lt;span&gt;&#123;&#123; title &#125;&#125;&lt;/span&gt;<br>      &lt;span class=&quot;iconfont title-icon&quot;&gt;&amp;#xe6eb;&lt;/span&gt;<br>      &lt;div class=&quot;select-con&quot;&gt;<br>        &lt;div class=&quot;select-item&quot; v-for=&quot;item in selectTypes&quot; :key=&quot;item.key&quot;&gt;<br>          &#123;&#123; item.text &#125;&#125;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;com-chart&quot; ref=&quot;trend_ref&quot;&gt;&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br></code></pre></td></tr></table></figure>

<p>使用计算属性 title 控制标题的内容和标题的可选择项</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs js">&lt;script&gt;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> &#123;<br>data () &#123;<br><span class="hljs-keyword">return</span> &#123;<br><span class="hljs-attr">chartInstance</span>: <span class="hljs-literal">null</span>,<br><span class="hljs-attr">allData</span>: <span class="hljs-literal">null</span>,<br><span class="hljs-attr">dataType</span>: <span class="hljs-string">&#x27;map&#x27;</span> <span class="hljs-comment">// 这项数据代表目前选择的数据类型, 可选值有map seller</span><br>commodity<br>&#125;<br>&#125;,<br><span class="hljs-attr">computed</span>: &#123;<br>selectTypes () &#123;<br><span class="hljs-keyword">if</span> (!<span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span> || ! <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>.<span class="hljs-property">type</span>) &#123;<br><span class="hljs-keyword">return</span> []<br>&#125; <span class="hljs-keyword">else</span> &#123;<br><span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>.<span class="hljs-property">type</span>.<span class="hljs-title function_">filter</span>(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> item.<span class="hljs-property">key</span> !== <span class="hljs-variable language_">this</span>.<span class="hljs-property">dataType</span><br>&#125;)<br>&#125;<br>&#125;,<br>title () &#123;<br><span class="hljs-keyword">if</span> (!<span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>) &#123;<br><span class="hljs-keyword">return</span> <span class="hljs-string">&#x27;&#x27;</span><br>&#125; <span class="hljs-keyword">else</span> &#123;<br><span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>[<span class="hljs-variable language_">this</span>.<span class="hljs-property">dataType</span>].<span class="hljs-property">title</span><br>&#125;<br>&#125;<br>&#125;,<br>......<br></code></pre></td></tr></table></figure></li>
<li><p>点击三角控制显示隐藏</p>
<p>增加一项变量控制可选容器的显示与隐藏</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs js">data () &#123;<br><span class="hljs-keyword">return</span> &#123;<br><span class="hljs-attr">showChoice</span>: <span class="hljs-literal">false</span> <span class="hljs-comment">// 控制可选面板的显示或者隐藏</span><br>&#125;<br></code></pre></td></tr></table></figure>

<p>使用指令 v-if 和点击事件的监听</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div class=&quot;com-container&quot;&gt;<br>    &lt;div class=&quot;title&quot;&gt;<br>      &lt;span&gt;&#123;&#123; title &#125;&#125;&lt;/span&gt;<br>      &lt;span class=&quot;iconfont title-icon&quot; @click=&quot;showChoice = !showChoice&quot;<br>        &gt;&amp;#xe6eb;&lt;/span<br>      &gt;<br>      &lt;div class=&quot;select-con&quot; v-if=&quot;showChoice&quot;&gt;<br>        &lt;div class=&quot;select-item&quot; v-for=&quot;item in selectTypes&quot; :key=&quot;item.key&quot;&gt;<br>          &#123;&#123; item.text &#125;&#125;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;com-chart&quot; ref=&quot;trend_ref&quot;&gt;&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br></code></pre></td></tr></table></figure></li>
<li><p>点击可选条目的控制</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div class=&quot;com-container&quot;&gt;<br>    &lt;div class=&quot;title&quot;&gt;<br>      &lt;span&gt;&#123;&#123; title &#125;&#125;&lt;/span&gt;<br>      &lt;span class=&quot;iconfont title-icon&quot; @click=&quot;showChoice = !showChoice&quot;<br>        &gt;&amp;#xe6eb;&lt;/span<br>      &gt;<br>      &lt;div class=&quot;select-con&quot; v-if=&quot;showChoice&quot;&gt;<br>        &lt;div<br>          class=&quot;select-item&quot;<br>          v-for=&quot;item in selectTypes&quot;<br>          :key=&quot;item.key&quot;<br>          @click=&quot;handleSelect(item.key)&quot;<br>        &gt;<br>          &#123;&#123; item.text &#125;&#125;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;com-chart&quot; ref=&quot;trend_ref&quot;&gt;&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>export default &#123;<br>......<br>methods: &#123;<br>handleSelect (key) &#123;<br>this.dataType = key<br>this.updateChart()<br>this.showChoice = false<br>&#125;<br>&#125;<br>&#125;<br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<p>将 <code>updateChart</code> 中, 之前写死的 map 变成 <code>dataType</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">const</span> valueArrs = <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>[<span class="hljs-variable language_">this</span>.<span class="hljs-property">dataType</span>].<span class="hljs-property">data</span><br><span class="hljs-keyword">const</span> seriesArr = valueArrs.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br>......<br><span class="hljs-attr">stack</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">dataType</span><br>&#125;<br>&#125;)<br></code></pre></td></tr></table></figure></li>
</ul>
<h2 id="分辨率适配"><a href="#分辨率适配" class="headerlink" title="分辨率适配"></a>分辨率适配</h2><p>分辨率适配主要就是在 <code>screenAdapter</code> 方法中进行, 需要获取图表容器的宽度,计算出标题字体大小, 将字体的大小赋值给<code> titleFontSize</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs js">&lt;script&gt;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> &#123;<br>data () &#123;<br><span class="hljs-keyword">return</span> &#123;<br><span class="hljs-attr">titleFontSize</span>: <span class="hljs-number">0</span><br>&#125;<br>&#125;,<br>......<br>screenAdapter () &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">$refs</span>.<span class="hljs-property">trend_ref</span>.<span class="hljs-property">offsetWidth</span> / <span class="hljs-number">100</span> * <span class="hljs-number">3.6</span><br>&#125;<br></code></pre></td></tr></table></figure>

<p>通过 <code>titleFontSize</code> 从而设置给标题文字的大小和图例的大小</p>
<ul>
<li><p>标题文字的大小</p>
<p>增加计算属性 comStyle 并设置给对应的 div ,如下:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;!-- 销量趋势图表 --&gt;<br>&lt;template&gt;<br>&lt;div class=&#x27;com-container&#x27;&gt;<br>&lt;div class=&quot;title&quot; :style=&quot;comStyle&quot;&gt;<br>&lt;span&gt;&#123;&#123; title &#125;&#125;&lt;/span&gt;<br>&lt;span class=&quot;iconfont title-icon&quot; @click=&quot;showChoice = !showChoice&quot;<br>:style=&quot;comStyle&quot;&gt;&amp;#xe6eb;&lt;/span&gt;<br>......<br>&lt;script&gt;<br>export default &#123;<br>......<br>computed: &#123;<br>......<br>comStyle () &#123;<br>return &#123;<br>fontSize: this.titleFontSize + &#x27;px&#x27;<br>&#125;<br>&#125;<br>&#125;,<br></code></pre></td></tr></table></figure></li>
<li><p>图例的大小</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs js">screenAdapter () &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">$refs</span>.<span class="hljs-property">trend_ref</span>.<span class="hljs-property">offsetWidth</span> / <span class="hljs-number">100</span> * <span class="hljs-number">3.6</span><br><span class="hljs-keyword">const</span> adapterOption = &#123;<br><span class="hljs-attr">legend</span>: &#123;<br><span class="hljs-attr">itemWidth</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span>,<br><span class="hljs-attr">itemHeight</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span>,<br><span class="hljs-attr">itemGap</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span>,<br><span class="hljs-attr">textStyle</span>: &#123;<br><span class="hljs-attr">fontSize</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> / <span class="hljs-number">2</span><br>&#125;<br>&#125;<br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">setOption</span>(adapterOption)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">resize</span>()<br>&#125;,<br></code></pre></td></tr></table></figure></li>
</ul>
<h2 id="细节调整"><a href="#细节调整" class="headerlink" title="细节调整"></a>细节调整</h2><ul>
<li><p>可选条目的背景色</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&#x27;less&#x27;</span> <span class="hljs-attr">scoped</span>&gt;</span><span class="language-css"></span><br><span class="language-css"><span class="hljs-selector-class">.title</span> &#123;</span><br><span class="language-css">......</span><br><span class="language-css"><span class="hljs-selector-class">.select-con</span> &#123;</span><br><span class="language-css"><span class="hljs-attribute">background-color</span>: <span class="hljs-number">#222733</span>;</span><br><span class="language-css">&#125;</span><br><span class="language-css"><span class="hljs-selector-class">.select-item</span> &#123;</span><br><span class="language-css"><span class="hljs-attribute">cursor</span>: pointer;</span><br><span class="language-css">&#125;</span><br><span class="language-css">&#125;</span><br><span class="language-css"></span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span><br></code></pre></td></tr></table></figure></li>
<li><p>增加标题左侧的小竖杆</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>&lt;div class=&#x27;com-container&#x27;&gt;<br>&lt;div class=&quot;title&quot; :style=&quot;comStyle&quot;&gt;<br>&lt;span&gt;&#123;&#123;&#x27;▎ &#x27; + title &#125;&#125;&lt;/span&gt;<br>&lt;span class=&quot;iconfont title-icon&quot; @click=&quot;showChoice = !showChoice&quot;<br>:style=&quot;comStyle&quot;&gt;&amp;#xe6eb;&lt;/span&gt;<br>&lt;div class=&quot;select-con&quot; v-if=&quot;showChoice&quot; :style=&quot;marginStyle&quot;&gt;<br>......<br>&lt;script&gt;<br>export default &#123;<br>......<br>computed: &#123;<br>marginStyle () &#123;<br>return &#123;<br>marginLeft: this.titleFontSize + &#x27;px&#x27;<br>&#125;<br>&#125;<br>&#125;,<br></code></pre></td></tr></table></figure></li>
</ul>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96%E9%A1%B9%E7%9B%AE/" class="category-chain-item">数据可视化项目</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/echarts/">#echarts</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>数据可视化项目四</div>
      <div>http://example.com/2022/11/17/数据可视化项目四/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>dayu</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年11月17日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/11/17/%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96%E9%A1%B9%E7%9B%AE%E4%B8%89/" title="数据可视化项目三">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">数据可视化项目三</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/11/16/%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96%E9%A1%B9%E7%9B%AE%E4%BA%94/" title="数据可视化项目五">
                        <span class="hidden-mobile">数据可视化项目五</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
